/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upn.sigemfi.vfi.bc;

import edu.upn.sigemfi.vfi.be.Caja;
import edu.upn.sigemfi.vfi.be.SaldoCaja;
import edu.upn.sigemfi.ope.be.Moneda;
import edu.upn.sigemfi.ope.be.Ventanilla;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Alex
 */
@Stateless
public class CajaFacade implements CajaFacadeLocal {

    @PersistenceContext(unitName = "edu.upn.sigemfi.vfi-ejbPU")
    private EntityManager em;

    public void create(Caja caja) {
        em.persist(caja);
    }

    public void edit(Caja caja) {
        em.merge(caja);
    }

    public void remove(Caja caja) {
        em.remove(em.merge(caja));
    }

    public Caja find(Object id) {
        return em.find(Caja.class, id);
    }

    public List<Caja> findAll() {
        return em.createQuery("select object(o) from Caja as o").getResultList();
    }

    public Caja buscarPorVentanilla(Ventanilla fidOpeVentanilla) {

        return (Caja) em.createQuery("SELECT object(o) FROM Caja as o WHERE o.fidOpeVentanilla = :fidOpeVentanilla ").setParameter("fidOpeVentanilla", fidOpeVentanilla).getSingleResult();
    }
//
//    public List findbySaldo() {
//       return em.createQuery("select c.nombre , d.monto , m.descripcion from Caja c inner join SaldoCaja d on c.idCaja = d.fidVfiCaja inner join Moneda m on d.fidOpeMoneda= m.idMoneda").getResultList();
//    }
}
